<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('order_edit_page_title'));
$this->headScript()->appendFile($this->APP_STATIC_SERVER.'/js/jquery.validate/jquery.validate.min.js');
?>
<style>
    .prefix_1.suffix_1 .t_a_bottom label{
        line-height: 16px;
    }
</style>
<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'order_order_list'); ?>"><?php echo $this->translator('order_list_breadcump'); ?></a></span>
    <span><a href="<?php echo $this->url(array('order_id' => $this->order->order_id), 'order_order_view'); ?>"><?php echo $this->translator('order_view_breadcump'); ?></a></span>
    <span><?php echo $this->translator('order_edit_breadcump'); ?></span>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>
<?php $order = $this->order?>

<form method="post" action="<?php //echo $this->url(array(), 'order_order_add'); ?>" id="addorderForm" class="t_a_form">
<div class="grid_12 t_a_bottom">
    <div class="clearfix t_a_bottom">
        <div class="grid_5">
            <a href="<?php echo $this->url(array('order_id' => $this->order->order_id), 'order_order_view'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('order_edit_btn_back'); ?></span></a>
        </div>
    </div>
</div>
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('order_id'); ?>:</label>
                <?php echo $order->order_invoice;?>
            </div>

            <div class="grid_5 omega">
                <label><?php echo $this->translator('order_status'); ?>:</label>
                <?php if($order->order_status == 'canceled'):?>
                <font color="Red"><?php echo $this->translator('order_'.$order->order_status);?></font>
                <?php else:?>
                <font color="Green"><?php echo $this->translator('order_'.$order->order_status);?></font>
                <?php endif;?>
            </div>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('order_created_date'); ?>:</label>
                <?php echo $order->order_created_date;?>
            </div>

            <?php if($this->role->name != 'employee'):?>
            <div class="grid_5 omega">
                <label><?php echo $this->translator('order_total_amount'); ?>:</label>
                <?php echo $order->order_total_amount;?> <?php echo $order->order_total_amount_currency;?>
            </div>
            <?php endif;?>
        </div>

        <hr />

        <?php if ($order->order_edited == 1):?>
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('order_modify_date'); ?>:</label>
                <?php echo $order->order_modified_date;?>
            </div>

            <?php if($this->role->name != 'employee'):?>
            <div class="grid_5 omega">
                <label><?php echo $this->translator('order_modify_amount'); ?>:</label>
                <?php echo $order->order_modify_amount;?> <?php echo $order->order_modify_amount_currency;?>
            </div>
            <?php endif;?>
        </div>

        <hr />
        <?php endif;?>

        <?php if($this->role->name != 'employee'):?>
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label>&nbsp;</label>
            </div>

            <div class="grid_5 omega">
                <label><?php echo $this->translator('order_total_shipping_cost'); ?>:</label>
                <?php echo $order->order_total_shipping_cost;?>USD
            </div>
        </div>

        <hr />
        <?php endif;?>

        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('order_customer'); ?>:</label>
                <?php echo $this->translator('order_customer_id'); ?>: <?php echo $order->customer_id;?>
            </div>

            <div class="grid_5 omega">
                <label><?php echo $this->translator('order_customer_name'); ?>:</label>
                <a href="<?php /*echo $this->url(array('user_id' => $order->user_id), 'account_customer_view');*/ ?>"><?php echo $order->full_name;?></a>
            </div>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('order_tracking_status'); ?>:</label>
                <?php echo $this->translator('order_'.$order->order_tracking_status);?>
            </div>
        </div>

        <hr />

    </div>
</div>
</form>

<div class="grid_12 t_a_ui_data_list_header">
    <div class="grid_4 alpha"><?php echo $this->translator('order_product_name'); ?></div>
    <div class="grid_3"><?php echo $this->translator('order_values'); ?></div>
    <div class="grid_2"><?php echo $this->translator('order_quantity'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('order_amount'); ?></div>
    <div class="grid_1 omega"><?php echo $this->translator('order_edit_action'); ?></div>
</div>
<div class="grid_12 t_a_bottom" id="ordersDetail">
    <?php foreach ($this->products as $row):?>
    <form id="orderDetail_<?php echo $row->order_detail_id;?>" action="" method="POST">
    <input type="hidden" value="<?php echo $row->order_detail_id?>" name="order_detail_id">
    <div class="clearfix t_a_ui_data_list_content">
        <div class="grid_4 alpha">
            <div style="padding-left: 5px">
                <?php if($row->order_detail_parent_id != null):?>
                    --- <?php echo $row->product_admin_name?>
                <?php else:?>
                    <?php echo $row->product_admin_name?>
                <?php endif;?>
                &nbsp;
            </div>
        </div>

        <div class="grid_3">
            <?php $arrAttributeValue = $this->arrAttributeValue[$row->product_id];?>
            <?php $i = 0; $additionalPants=0; foreach ($this->arrAttribute[$row->product_id] as $row1):?>
                <?php $i++; if(count($this->arrAttribute[$row->product_id]) == $i):?>
                    <?php $str = '';?>
                <?php else :?>
                    <?php $str = '<br>';?>
                <?php endif;?>
                <?php echo $row1->attribute_type_admin_name;?>
                <select name="value_type_id[]" <?php if($row1->attribute_type_admin_name == 'Additional pants') echo 'id="cmb_value_type"';?>>
                    <?php foreach ($arrAttributeValue[$row1->attribute_type_id] as $row2):?>
                        <option value="<?php echo $row2->value_type_id;?>" <?php if(strstr($row->product_value_type_id_chain,','.$row2->value_type_id.',')) echo 'selected';?> rel="<?php echo $row2->value_type_price;?>">
                            <?php echo $row2->value_type_name;?>
                        </option>
                        <?php
                            if(strstr($row->product_value_type_id_chain,','.$row2->value_type_id.',')){
                                $additionalPants += $row2->value_type_price;
                            }
                        ?>
                    <?php endforeach;?>
                </select>
                <?php echo $str;?>
            <?php endforeach;?>
            &nbsp;
        </div>

        <div class="grid_2">
            <?php if($row->order_detail_parent_id != null || $row->product_bundle == 1):?>
            <?php else:?>
                <input type="text" value="<?php echo $row->order_detail_quantity?>" name="order_detail_quantity">
            <?php endif;?>
            &nbsp;
        </div>

        <div class="grid_2 omega">
            <?php if($row->order_detail_parent_id != null):?>
            <?php else:?>
                <?php echo $row->order_detail_quantity*$row->product_price+$additionalPants;?> <?php echo $row->product_price_currency?>
                <input type="hidden" value="<?php echo $row->product_price?>" name="product_price">
                <input type="hidden" value="<?php echo $row->product_shipping_price?>" name="product_shipping_price">
                <input type="hidden" value="<?php echo $row->order_detail_quantity*$row->product_price?> <?php echo $row->product_price_currency?>" name="old_product_amount">
                <input type="hidden" value="<?php echo $row->order_detail_quantity*$row->product_shipping_price?>" name="old_product_shipping_price">
                <input type="hidden" value="" name="new_additional_price" id="new_additional_price">
                <input type="hidden" value="<?php echo $additionalPants;?>" name="old_additional_price" id="old_additional_price">
            <?php endif;?>
            &nbsp;
        </div>
        <div class="grid_1 omega">
            <?php if($row->product_bundle == 1):?>
            <?php else:?>
            <input type="submit" value="<?php echo $this->translator('order_edit_action_change'); ?>">
            <?php endif;?>
            &nbsp;
        </div>
    </div>
    </form>
    <?php endforeach;?>
</div>

<script type="text/javascript">

$(document).ready(function() {

    $("#cmb_value_type").bind('change', function(){
        var newAdditionalPrice = $(this).find(':selected').attr('rel');
        $('#new_additional_price').attr('value',newAdditionalPrice);
    });
})
</script>
